#include "CustomHorizontalHeader.h"


CustomHorizontalHeader::CustomHorizontalHeader(Qt::Orientation orientation, QWidget *parent)
    : QHeaderView(orientation, parent)// , resizingSection(-1), initialPos(0)
{
    setMouseTracking(true); // 启用鼠标跟踪
}



void CustomHorizontalHeader::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
{
    QHeaderView::paintSection(painter, rect, logicalIndex);

    QTableView *tableView = qobject_cast<QTableView*>(parent());
    if (!tableView) return;

    QItemSelectionModel *selectionModel = tableView->selectionModel();
    if (!selectionModel) return;

    // 检查当前列是否被选中
    if (selectionModel->isColumnSelected(logicalIndex, QModelIndex())) {
        QIcon icon(":/Resource/action_icon.png"); // 替换为你的图标路径
        icon.paint(painter, rect, Qt::AlignCenter);
    }

//    QModelIndex index = tableView->model()->index(logicalIndex, 0);
//    if (selectionModel->isSelected(index)) {
//        QIcon icon(":/Resource/action_icon.png"); // 替换为你的图标路径
//        icon.paint(painter, rect, Qt::AlignCenter);
//    }

//    // 获取表格视图和选择模型
//    QTableView *tableView = qobject_cast<QTableView*>(parent());
//    if (!tableView) return;

//    QItemSelectionModel *selectionModel = tableView->selectionModel();
//    if (!selectionModel) return;

//    // 创建索引
//    QModelIndex index = tableView->model()->index(logicalIndex, 0);
//    if (selectionModel->isSelected(index)) {
//        // 如果选中，绘制图标
//        QIcon icon(":/Resource/action_icon.png"); // 替换为你的图标路径
//        icon.paint(painter, rect, Qt::AlignCenter);
//    }
}
